package com.itheima.reggie.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    //释放前端资源


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

    /**
     * converters : springmvc的转换器列表， 默认springmvc有10个转换器，你如果需要新增一个转换器，需要把转换器添加到converters
     * @param converters
     */
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { //springmvc的10个转换器里面有转换long的转换器。
        // //创建消息转换器对象
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        //设置消息转换器底层转换对象，
        mappingJackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());

        //把消息转换器添加到转换器列表
        converters.add(0,mappingJackson2HttpMessageConverter);
    }
}
